//GameStateIntro class
#include "GameStateIntro.h"
#include "GameStateManager.h"

GameStateIntro GameStateIntro::Instance;

GameStateIntro::GameStateIntro() {
    Surf_Logo = NULL;
}

//OnKeyUp-
void GameStateIntro::OnKeyUp(SDLKey sym, SDLMod mod, Uint16 unicode) {
    switch(sym) {
        case SDLK_RETURN: {
            GameStateManager::SetActiveGameState(GAMESTATE_MAP);
            break;
        }
        case SDLK_SPACE: {
            displayControls = true;
            break;
            }
        default: {
        }

        }
}

void GameStateIntro::OnActivate() {
    displayEnter = false;
    promptControls = false;
    displayControls = false;
    // Load Simple Logo
    Surf_Logo = Surface::OnLoad("intro.png");
    //Load font
    Surf_Font = tx.OnLoad("VeraBd.ttf", 24);
    StartTime = SDL_GetTicks();

}

void GameStateIntro::OnDeactivate() {
    if(Surf_Logo) {
        SDL_FreeSurface(Surf_Logo);
    }
    Surf_Logo = NULL;
    //Close font
    if (Surf_Font)
        TTF_CloseFont(Surf_Font);
    Surf_Font = NULL;
    //this creates a black box to cover old graphics (due to bug?)
    SDL_FillRect(SDL_GetVideoSurface(), NULL, 0);
}

void GameStateIntro::OnLoop() {
   // if(StartTime + 1000 < SDL_GetTicks()) {
        displayEnter = true;
        promptControls = true;

   // }

}

void GameStateIntro::OnRender(SDL_Surface* Surf_Display) {
    if(Surf_Logo) {
        Surface::OnDraw(Surf_Display, Surf_Logo, 0, 0);
    }
    if (displayEnter)
        tx.OnRender(Surf_Display, Surf_Font, 190   , 400, "Press Enter To Start");
    if (promptControls)
        tx.OnRender(Surf_Display, Surf_Font, 190   , 450, "Press Space For Controls");
    if (displayControls){
        SDL_FillRect(SDL_GetVideoSurface(), NULL, 0);
        tx.OnRender(Surf_Display, Surf_Font, 190   , 400, "Press Enter To Start");
        tx.OnRender(Surf_Display, Surf_Font, 100   , 100, "Arrow Keys to Move");
        tx.OnRender(Surf_Display, Surf_Font, 100   , 130, "Space to Exit Battles");
        tx.OnRender(Surf_Display, Surf_Font, 100   , 160, "Q to quit the game");
    }
}



GameStateIntro* GameStateIntro::GetInstance() {
    return &Instance;
}

